package com.example.lotapp.dataAdapter;

import java.util.HashMap;

import com.example.lotapp.utils.DataUtils;

public class FootballDataHelper {
	private static final HashMap<String, String> sKeyMap = new HashMap<String, String>();
	static {
		sKeyMap.put("MNo", "MatchId");
		sKeyMap.put("MID", "MatchId");
		sKeyMap.put("MatchId", "HistoryId");
		sKeyMap.put("issue", "IssueId");
		sKeyMap.put("IssueID", "IssueId");
		sKeyMap.put("NMm", "MatchName");
		sKeyMap.put("ETime", "MatchEndtime");
		sKeyMap.put("HTeam", "HomeTeam");
		sKeyMap.put("VTeam", "AwayTeam");
		sKeyMap.put("HomeRank", "HomeRank");
		sKeyMap.put("AwayRank", "AwayRank");
		sKeyMap.put("Rq", "Offset");
		sKeyMap.put("SpSPF", "SpSpf");
		sKeyMap.put("SpRQSPF", "SpRqspf");
		sKeyMap.put("SpZJQ", "SpZjq");
		sKeyMap.put("SpCBF", "SpCbf");
		sKeyMap.put("SpBQC", "SpBqc");
		sKeyMap.put("AvgSP", "SpAvg");
		sKeyMap.put("Score", "Score");
		sKeyMap.put("Hrz", "Score");
	}

	public static String getAdaptKey(String originKey) {
		if (sKeyMap.containsKey(originKey)) { 
			return sKeyMap.get(originKey);
		}
		return "";
	}
	
	public static long makeScoreBitData(String score, String helfScore) {
		long ans = 0;
		String[] scores = score.split(":");
		String[] helfScores = helfScore.split(":");
		if (scores.length != 2 || helfScores.length != 2) {
			return ans;
		}
		long homeScore = DataUtils.parseLong(scores[0], 0);
		long awayScore = DataUtils.parseLong(scores[1], 0);
		long homeHelfScore = DataUtils.parseLong(helfScores[0], 0);
		long awayHelfScore = DataUtils.parseLong(helfScores[1], 0);
		
		ans = homeScore | (awayScore << 15) | (homeHelfScore << 30) | (awayHelfScore << 45);
		
		return ans;
	}
	
	public static long makeSingleBitData(long spf, long rqspf, long zjq, long cbf, long bqc) {
		long ans = spf | (rqspf << 1) | (zjq << 2) | (cbf << 3) | (bqc << 4);
		return ans;
	}
	
	public static boolean isSingleSpf(long singleBit) {
		return (singleBit & 1) != 0;
	}
	
	public static boolean isSingleRqspf(long singleBit) {
		return (singleBit & (1 << 1)) != 0;
	}
	
	public static boolean isSingleZjq(long singleBit) {
		return (singleBit & (1 << 2)) != 0;
	}
	
	public static boolean isSingleCbf(long singleBit) {
		return (singleBit & (1 << 3)) != 0;
	}
	
	public static boolean isSingleBqc(long singleBit) {
		return (singleBit & (1 << 4)) != 0;
	}
}
